﻿using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Prototype_C_Sharp
{

    class Program
    {
        static void Main(string[] args)
        {

            //test
            {
                Person person = new Person();
                
                person.id = 123;
                person.name = "jc";

                //var clone = person.Clone();
                //var deepClone = person.DeepClone();

                //person.t.sex = "woman";
                //person.id = 321;
                //person.name = "laya";

                var sw = Stopwatch.StartNew();
                List<Person> list = new List<Person>();
                sw.Start();
                for( int i =0;i<10000;i++ )
                {
                    Person t = new Person();
                    list.Add(t);
                }
                sw.Stop();
                Console.WriteLine($"正常创建耗时 耗时{sw.ElapsedMilliseconds}ms");


                sw = Stopwatch.StartNew();
                List<Person> list2 = new List<Person>();
                sw.Start();
                for (int i = 0; i < 10000; i++)
                {
                    Person t = (Person)person.DeepClone();
                    list2.Add(t);
                }
                sw.Stop();
                Console.WriteLine($"原型创建耗时 耗时{sw.ElapsedMilliseconds}ms");

                //Preformance("浅拷贝", () => { person.Clone(); }, 10000);
                // Preformance("深拷贝", () => person.DeepClone(), 10000);

            }

            Console.Read();

        }

        private static void Preformance(string type, Action func, int times = 1)
        {
            var sw = Stopwatch.StartNew();
            sw.Start();
            for (int i = 0; i < times; i++)
                func.Invoke();
            sw.Stop();
            Console.WriteLine($"[{type}]执行{times}次, 耗时{sw.ElapsedMilliseconds}ms");
        }

    }
}
